package com.kylin.common.core.config.support;

import com.alibaba.fastjson2.filter.PropertyFilter;
import com.kylin.common.core.annotation.JSONSkipIfNull;

/**
 * NULL序列化过滤
 * @author wuhao
 * @version 1.0 - 2024/10/21
 */
public class NullPropertyFilter implements PropertyFilter {
    @Override
    public boolean apply(Object source, String name, Object value) {
        try {
            if (source.getClass().getDeclaredField(name).isAnnotationPresent(JSONSkipIfNull.class)) {
                return value != null;
            }
        } catch (NoSuchFieldException e) {
//            throw new RuntimeException(e);
            return false;
        }
        return true;
    }
}
